package cn.ex;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Ex9 {
    public static void main(String[] args) {
        int i = 0;


        Set<String> set = new HashSet<>();
        while (set.size()!=11) {
            ++i;
            String str = getStr();
            if (sum(str) == 100) {
                //System.out.printf("%s = %d%n", str, sum(str));
                set.add(str);
            }
        }

        for(String s :set){
            System.out.printf("%s = 100%n",s);
        }
        System.out.println(i);
    }

    public static int sum(String str) {
        int sum = 0;
        Pattern p = Pattern.compile("[0-9]+|\\-[0-9]+");
        Matcher m = p.matcher(str);
        while (m.find()) {
            sum += Integer.parseInt(m.group());
        }
        return sum;
    }

    public static String getStr() {
        StringBuilder sbu = new StringBuilder();
        String[] op = {"+", "-", ""};
        Random rand = new Random();
        for (int i = 1; i < 9; i++) {
            sbu.append(i + op[rand.nextInt(op.length)]);
        }
        sbu.append(9);
        return sbu.toString();
    }
}
